import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
   {
    path:'/',
    component:()=>import('@/views/layout/index.vue'),
    children:[
      {
        path:'',
        component:()=>import('@/views/home/index.vue')
      },
      {
        path:'category/:id',
        component:()=>import('@/views/category/index.vue')
        
      },
      {
        path:'category/sub/:id',
        component:()=>import('@/views/category/categorySub/index.vue')
      },
      {
        path:'Detail/:id',
        component:()=>import('@/views/Detail/index.vue')
      },
      {
        path:'Cart',
        component:()=>import('@/views/CartList/index.vue')
      },
      {
        path:'cheackout',
        component:()=>import('@/views/cheackOut/index.vue')
      },
      {
        path:'Pay',
        component:()=>import('@/views/Pay/index.vue')
      },
      {
        path:'paycallback',
        component:()=>import('@/views/Pay/PayBack/index.vue')
      },
      {
        path:'/member',
        component:()=>import('@/views/Menber/index.vue'),
        //重定向
        redirect:'/member/user',
        children:[
          {
            path:'user',
            component:()=>import('@/views/Menber/components/UserInfo.vue')
          },
          {
            path:'order',
            component:()=>import('@/views/Menber/components/UserOrder.vue')
          }
        ]
      }
    ]
   },
   {
    path:'/login',
    component:()=>import('@/views/login/index.vue')
   }
  ],
  // 设置滚动
  scrollBehavior(to, from, savedPosition) {
  //  跳转滚动到顶部
  return { top: 0
      }
  }
})

export default router
